package display;

import java.awt.event.*;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.*;

import deckbuilder.Flashcard;

public class Style2 
{
	
	public Style2()
	{
		
	}
	
	public void buildGUI()
	{
		final JFrame frame = new JFrame();
		JPanel card = new JPanel();
		//JPanel timer = new JPanel();
		JPanel buttons = new JPanel();
		JPanel result = new JPanel();
		
		GridBagConstraints c = new GridBagConstraints();
		
		final Flashcard flashcards = new Flashcard();
		flashcards.deck.buildDeckFromFile("test.txt");
		flashcards.newLabels();
		flashcards.newButtons();
		flashcards.next.setVisible(false);
		flashcards.result.setVisible(false);
		
		frame.setLayout(new GridBagLayout());
		frame.setSize(350, 200);
		frame.setLocationRelativeTo(null);
		
		flashcards.term.setVisible(true);
		flashcards.def.setVisible(false);
		  
	    c.gridx = 0;
	    c.gridy = 0;
		frame.add(card, c);
		
	    c.gridx = 0;
	    c.gridy = 1;
		frame.add(buttons, c);
		
		 c.gridx = 0;
		 c.gridy = 2;
		 frame.add(result, c);
		
		card.add(flashcards.term);
				
		buttons.add(flashcards.op1);
		buttons.add(flashcards.op2);
		buttons.add(flashcards.op3);
		
		result.add(flashcards.result);
		result.add(flashcards.next);
		
		frame.setVisible(true);

		flashcards.op1.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {
				
					flashcards.result.setVisible(true);
				
					if(flashcards.op1.getText().equals(flashcards.def.getText()))
					{
						flashcards.result.setText("Correct!");
					}
					
					else
					{
						flashcards.result.setText("Incorrect");
					}
					
					flashcards.next.setVisible(true);
			}
		});

		flashcards.op2.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {
				
				flashcards.result.setVisible(true);
				
				if(flashcards.op2.getText().equals(flashcards.def.getText()))
				{
					flashcards.result.setText("Correct!");
				}
				
				else
				{
					flashcards.result.setText("Incorrect");
				}
				
				flashcards.next.setVisible(true);
			}
		});
		
		flashcards.op3.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {
				
				flashcards.result.setVisible(true);
				
				if(flashcards.op3.getText().equals(flashcards.def.getText()))
				{
					flashcards.result.setText("Correct!");
				}
				
				else
				{
					flashcards.result.setText("Incorrect");
				}
				
				flashcards.next.setVisible(true);
			}
		});
		
		flashcards.next.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {
				flashcards.nextCard();
				flashcards.newLabels();
				flashcards.newButtons();
				flashcards.next.setVisible(false);
				flashcards.result.setVisible(false);
			}
		});
	}

}
